<template>
  <div class="comment-reply">
    <van-nav-bar
      :title="
        commentData.reply_count
          ? commentData.reply_count + '条回复'
          : '暂无回复'
      "
    >
      <van-icon slot="left" name="cross" @click="$emit('close')" />
    </van-nav-bar>

    <div class="scroll-wrap">
      <!-- 当前评论项 -->
      <van-cell value="当前评论项"></van-cell>
      <comment-item :comment="commentData"></comment-item>
      <!-- /当前评论项 -->

      <!-- 评论的回复列表 -->
      <van-cell value="回复列表">222 </van-cell>
      <comment-list
        :source-id="commentData.com_id"
        type="c"
        :list="commentList"
      ></comment-list>
      <!-- /评论的回复列表 -->
    </div>

    <!-- 底部区域 -->
    <div class="reply-bottom">
      <van-button class="write-btn" size="small" round @click="replyShow = true"
        >写评论</van-button
      >
    </div>
    <!-- /底部区域 -->

    <!-- 发布评论 -->
    <van-popup v-model="replyShow" position="bottom">
      <comment-post
        @postSuccess="postSuccess"
        :target-id="commentData.com_id"
        type="c"
      ></comment-post>
    </van-popup>
    <!-- /发布评论 -->
  </div>
</template>

<script>
import CommentItem from "./comment-item.vue";
import CommentList from "./comment-list.vue";
import CommentPost from "./comment-post.vue";
export default {
  name: "CommentReply",
  components: { CommentItem, CommentList, CommentPost },
  data() {
    return {
      replyShow: false,
      commentList: [], //当前评论回复列表
    };
  },
  props: {
    commentData: {
      type: Object,
      required: true,
    },
  },
  methods: {
    postSuccess(val) {
      this.commentList.unshift(val);
      this.replyShow = false;
      this.commentData.comment_reply++;
    },
  },
};
</script>

<style scoped lang="less">
.scroll-wrap {
  position: fixed;
  top: 92px;
  left: 0;
  right: 0;
  bottom: 88px;
  overflow-y: auto;
}

.reply-bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  border-top: 1px solid #d8d8d8;
  .write-btn {
    width: 60%;
  }
}
</style>
